﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Practices.Unity;
using Praxis.Entities;
using Praxis.BusinessLogic;

namespace Praxis.UI
{
    public partial class FrmMttoCliente : Form
    {
        [Dependency]
        public IClienteBL clienteBL { get; set; }

        bool bandera;

        public FrmMttoCliente()
        {
            InitializeComponent();
            this.BuildUp();
        }

        public CLIENTE CurrentCliente { get; set; }

        public void Nuevo()
        {
            bandera = true;
            cLIENTEBindingSource.AddNew();
        }

        public void Editar()
        {
            bandera = false;
            cLIENTEBindingSource.DataSource = CurrentCliente;
        }

        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            CLIENTE currentCliente = cLIENTEBindingSource.Current as CLIENTE;
            if (currentCliente != null)
            {
                if (bandera == true)
                {
                    clienteBL.AddCliente(currentCliente);
                    MessageBox.Show("Registro Correcto", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
                if (bandera == false)
                {
                    clienteBL.UpdateCliente(currentCliente);
                    MessageBox.Show("Modificacion Correcta", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
            }
        }

        private void FrmMttoCliente_Load(object sender, EventArgs e)
        {

        }
    }
}
